﻿using Leeder.Logger;
using LeederGlobal;
using SPSAndong.Business;
using SPSAndong.Handle;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace SPSAndong.Forms
{
    public partial class FrmOtherSet : UIPage
    {
        bool isLoad = true;      //判断窗体是否首次加载
        public LogOperate LogObj => Log.GetLogger(this.GetType());
        SystemSetupBLL systemSetupBLL = new SystemSetupBLL();
        SPSAndongHandler sPSAndongHandler;

        public FrmOtherSet()
        {
            InitializeComponent();
        }

        private void FrmOtherSet_Load(object sender, EventArgs e)
        {
            if (!isLoad)
                return;
            isLoad = false;
            sPSAndongHandler = SPSAndongHandler.getInstance();
            LoadOther();
        }

        private void LoadOther()
        {
            var sysSet = systemSetupBLL.GetModel();
            txtExceptionCall.Text = sysSet.ExceptionCall.ToString();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission > 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            var sysSet = systemSetupBLL.GetModel();
            sysSet.ExceptionCall = int.Parse(txtExceptionCall.Text);
            var result = systemSetupBLL.Update(sysSet);
            if (result.IsSuccess)
                UIMessageTip.ShowOk("保存成功");
            else
            {
                LogObj.Error("保存失败(" + result.Dsca + ")");
                UIMessageBox.ShowError("保存失败！");
            }
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            sPSAndongHandler.StopVoiceAll();
        }
    }
}
